package com.ciaojian.core.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ciaojian.core.mapper.ChargeLogMapper;
import com.ciaojian.core.model.ChargeLog;

import javax.annotation.Resource;

/**
 * @author oxiny
 */
public abstract class ChargeLogService extends ServiceImpl<ChargeLogMapper, ChargeLog> {
    @Resource
    private ChargeUserService chargeUserService;

    /**
     * 变更余额
     *
     * @param userId 用户ID
     * @param amount 数额
     * @param dir    方向 0支出 1收入 2冻结
     * @return 更改结果
     */
    public Boolean chargeChange(Integer userId,
                                Integer amount,
                                Integer targetType,
                                Integer dir,
                                Integer orderId) {
        // 余额
        Integer balance = chargeUserService.getBalance(userId);
        // 变更结果
        Boolean result = chargeUserService.chargeChange(userId, amount, dir, targetType, orderId);
        if (result) {
            return true;
        } else {
            // 失败
            return false;
        }
    }


}
